package main

import (
	"github.com/gotk3/gotk3/glib"
	"github.com/gotk3/gotk3/gtk"
	"log"
	"os"
)

func main() {
	// 接受两个参数一个是 应用标识，其一般使用你域名的倒序形式;
	//另一个是GApplicationFlags，其为了满足你对应用的特定需求。
	//通常就像实例代码一样写glib.APPLICATION_FLAGS_NONE就可以了。
	const appId = "com.nayoso.example"
	// 每个gtk3程序都需要一步
	app, err := gtk.ApplicationNew(appId, glib.APPLICATION_FLAGS_NONE)

	if err != nil {
		log.Fatal("Could not create application.", err)
	}

	//为activate事件绑定函数, activate会在程序启动时触发，也就是app.Run()时
	// 创建窗口
	_ = app.Connect("activate", func() {
		createWindow(app)
	})

	app.Run(os.Args) //运行gtkApplication
}

func createWindow(application *gtk.Application) {
	appWindow, err := gtk.ApplicationWindowNew(application) //创建window控件

	if err != nil {
		log.Fatal("Could not create application window.", err)
	}
	//设置窗口属性
	appWindow.SetTitle("Basic Application.")
	appWindow.SetDefaultSize(400, 400)
	//显示窗口
	appWindow.Show()
}

/*
import (
	"log"

	"github.com/gotk3/gotk3/gtk"
)

func main() {
	// Initialize GTK without parsing any command line arguments.
	gtk.Init(nil)

	// Create a new toplevel window, set its title, and connect it to the
	// "destroy" signal to exit the GTK main loop when it is destroyed.
	win, err := gtk.WindowNew(gtk.WINDOW_TOPLEVEL)
	if err != nil {
		log.Fatal("Unable to create window:", err)
	}
	win.SetTitle("Simple Example")
	win.Connect("destroy", func() {
		gtk.MainQuit()
	})

	// Create a new label widget to show in the window.
	l, err := gtk.LabelNew("Hello, gotk3!")
	if err != nil {
		log.Fatal("Unable to create label:", err)
	}

	// Add the label to the window.
	win.Add(l)

	// Set the default window size.
	win.SetDefaultSize(800, 600)

	// Recursively show all widgets contained in this window.
	win.ShowAll()

	// Begin executing the GTK main loop.  This blocks until
	// gtk.MainQuit() is run.
	gtk.Main()
}

*/
